<template>
  <el-dialog
    :title="title"
    destroy-on-close
    append-to-body
    :visible.sync="show"
    width="1000px"
    :before-close="cancel">
    <el-table
      :row-class-name="({ row }) => handleRowClassName(row)"
      show-summary
      :summary-method="handleSum"
      ref="TableRef"
      :data="tabelDeta">
      <el-table-column show-overflow-tooltip :label="$t('平台')" align="center" prop="type">
        <template slot-scope="{ row }">
          <span v-if="row.type == 1">
            <!-- 亚马逊 -->
            {{ $t('亚马逊') }}
          </span>
          <span v-if="row.type == 2">
            <!-- 乐天 -->
            {{ $t('乐天') }}
          </span>
          <span v-if="row.type == 3">
            <!-- 雅虎拍卖 -->
            {{ $t('雅虎拍卖') }}
          </span>
          <span v-if="row.type == 4">
            <!-- 雅虎商城 -->
            {{ $t('雅虎商城') }}
          </span>
          <span v-if="row.type == 5">
            <!-- 煤炉(法人) -->
            {{ $t('煤炉(法人)') }}
          </span>
          <span v-if="row.type == 6">
            <!-- 沃尔玛 -->
            {{ $t('沃尔玛') }}
          </span>
          <span v-if="row.type == 7">
            <!--  7-煤炉(个人) -->
            {{ $t('煤炉(个人)') }}
          </span>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip :label="$t('店铺名')" align="center" prop="shopName" />
      <el-table-column show-overflow-tooltip :label="$t('订单号')" align="center" prop="orderNo" />
      <el-table-column show-overflow-tooltip :label="$t('包裹号')" align="center" prop="packageNo">
      </el-table-column>
      <!-- 取消订单 -->
      <el-table-column show-overflow-tooltip :label="$t('取消订单')" align="center" prop="delFlag">
        <template slot-scope="{ row }">
          <!-- 取消订单 0：否，1：是 -->
          <div style="color: green" v-if="row.delFlag == 0">
            {{ $t('否') }}
          </div>
          <div style="color: red" v-if="row.delFlag == 2">
            {{ $t('是') }}
          </div>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip :label="$t('营业额')" align="center" prop="turnover" />
      <el-table-column show-overflow-tooltip :label="$t('手续费')" align="center" prop="commission" />
    </el-table>
  </el-dialog>
</template>
<script>
import handleTableSum from '@/utils/handleSum'

import { billSellerFeeInfo } from '@/api/bill/seller'
export default {
  activated() {
    this.$nextTick(() => this.$refs['TableRef']?.doLayout())
  },
  props: {
    data: {
      type: Object,
      default: () => {},
    },
    title: {
      type: String,
    },
    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      tabelDeta: [],
    }
  },
  methods: {
    handleRowClassName(row) {
      if (row.delFlag == 2) {
        return 'delFlag-2'
      }
    },
    handleSum(param) {
      /**
       * 需要进行统计的字段
       */
      const data = handleTableSum(param, ['turnover', 'commission'], '合计', 0)
      console.log(`data ==>`, JSON.parse(JSON.stringify(data)))
      return data
    },

    cancel() {
      console.log('执行了')
      this.$emit('update:show', false)
    },
  },
  watch: {
    show: function (params) {
      if (params) {
        billSellerFeeInfo({ id: this.data.id, type: 3 }).then((res) => {
          this.tabelDeta = res.data.handlingFeeList
        })
      }
    },
  },
}
</script>
